package org.lzfto.flink.demo.controller;

import java.util.Map;

import org.lzfto.flink.demo.business.flinkTest.test.SimpleTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Lazy
@RestController
@RequestMapping("/flink-tests")
public class FlinkTestController {
    private final SimpleTestService demoApp;

    public FlinkTestController(@Autowired SimpleTestService demoApp) {
        this.demoApp = demoApp;
    }

    @GetMapping
    public Object getTests() {
        return demoApp.getTasks();
    }

    @RequestMapping(value="/run/{testId}",method={RequestMethod.POST,RequestMethod.GET})
    public Object runTest(@PathVariable int testId,@RequestBody Map<String,Object> params) {
        return demoApp.runTest(testId,params);
    }
    
    @RequestMapping(value="/stopMqtt",method={RequestMethod.POST,RequestMethod.GET})
    public Object stopMqtt(@RequestParam Integer taskId) {
        return demoApp.cleanTest(taskId);
    }
    
}
